package com.hthy.futures.ui;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.hthy.futures.R;
import com.hthy.futures.base.CommonAdapter;
import com.hthy.futures.bean.Goods;

/**
 * 类型选择
 * Author:  Mr.bingley
 * Version:
 * Date:  2017/4/18
 */

public class GoodsTypeListDialog extends BaseDialog{
    Context mcontext;
    private ListView mListView;
    private CommonAdapter<String> mChooseGoodCommonAdapter;
    OnGoodsItemSelectedListener mOnGoodsItemSelectedListener;

    public GoodsTypeListDialog(Context context) {
        super(context);
        mcontext = context;
    }

    @Override
    protected void initView(View contentView) {
        mListView = (ListView) contentView.findViewById(R.id.listView);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String selectGoodItem = mChooseGoodCommonAdapter.getItem(position);
                mOnGoodsItemSelectedListener.select(selectGoodItem);
                dismiss();
            }
        });
        contentView.findViewById(R.id.ll_container).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    protected int getContentView() {
        return R.layout.dialog_goodtype_list;
    }

    public void setGoodsTypeAdapter(CommonAdapter<String> chooseGoodCommonAdapter) {
        this.mChooseGoodCommonAdapter = chooseGoodCommonAdapter;
        mListView.setAdapter(chooseGoodCommonAdapter);
    }

    public void setOnGoodsItemSelectedListener(OnGoodsItemSelectedListener goodsItemSelectedListener) {
        mOnGoodsItemSelectedListener = goodsItemSelectedListener;
    }

    public interface OnGoodsItemSelectedListener {
        void select(String seletStr);
    }
}
